<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>用户信息</title>
    <link rel="stylesheet" href="css/bootstrap.css">
    <script src="js/jquery.js" type="text/javascript"></script>
    <script src="js/bootstrap.js" type="text/javascript"></script>
    <script src="js/jsrender.js" type="text/javascript"></script>
    <script src="js/common.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function(){
            if(localStorage.getItem("token")==null){
                window.location.href="login.html"
            }
            var arrayurl = window.location.search.substring(1).split("&")
            var Account = arrayurl[0].split("=")[1]
            if(Account==undefined)
            {
                Account=localStorage.getItem("account")
            }
            $.ajax({
                url: GC.bctx + Account,
                type: "GET",
                headers: {"Authorization": localStorage.getItem("token")},
                success:function(r){
                    if(r.successed){
                        $("#userId").val(r.data.userId)
                        $("#userAccount").val(r.data.userAccount)
                        $("#userPassword").val(r.data.userPassword)
                        $("#userTelephone").val(r.data.userTelephone)
                        $("#userPosition").val(r.data.userPosition)
                    }else{
                        alert(r.message)
                    }
                }
            })
            $("form").submit(function(){
                if(localStorage.getItem("account")!=$("#userAccount").val()&&localStorage.getItem("position")==0)
                {
                    alert("您的权限不足")
                    return false
                }
                $.ajax({
                    url: GC.bctx + "/update/" + localStorage.getItem("account"),
                    type:"PUT",
                    data:$("form").serialize(),
                    headers: {"Authorization": localStorage.getItem("token")},
                    success:function(r){
                        if(r.successed){
                            //修改成功，转向显示所有部门页面
                            alert(r.message)
                            window.location.href="managers.html"
                        }else{
                            //修改失败，显示失败信息
                            alert(r.message)
                        }

                    }
                })
                return false
            })
        })
    </script>
</head>
<body>
<div class="container-fluid">
    <h1>用户信息</h1>
    <hr/>
    <form>
        <table>
            <tr class="d-none">
                <td >编号：</td>
                <td><input id="userId" name="userId" type="text"/></td>
                <td><span class="c-r">*</span></td>
            </tr>
            <tr>
                <td>账号：</td>
                <td><input id="userAccount" name="userAccount" readonly="true" type="text"/></td>
                <td><span class="c-r">*</span></td>
            </tr>
            <tr class="d-none">
                <td >密码：</td>
                <td><input id="userPassword" name="userPassword" type="password"/></td>
                <td><span class="c-r">*</span></td>
            </tr>
            <tr>
                <td>电话：</td>
                <td><input id="userTelephone" name="userTelephone" type="text"/></td>
                <td><span class="c-r">*</span></td>
            </tr>
            <tr>
                <td>职位权限：</td>
                <td><select id="userPosition" name="userPosition" readonly="true" disabled="disabled">
                    <option value="0">普通员工</option>
                    <option value="1">管理人员</option>
                </select></td>
                <td><span class="c-r">*</td>
            </tr>
            <tr>
                <td colspan="3" class="text-center">
                    <input type="submit" value="修改"/>
                    <a href="updatePassword.html" id="managerdetail" target="main">修改密码</a>
                </td>
            </tr>
        </table>
    </form>
</div>
</body>
</html>